<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <title>自动生成v1.0.1</title>
  <!-- 引入 Element UI 样式 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <style>
    .wrap {
        width: 50%;
        margin: 60px auto;
    }
    @media screen and (max-width: 1024px) {
        .wrap {
            width: 70%;
            margin: 40px auto;
        }
    }
    @media screen and (max-width: 740px) {
        .wrap {
            width: 100%;
            margin: 20px auto;
        }
    }
    .result {

    }
    .title {
        color: #333;
        margin-bottom: 10px;
        font-weight: 600;
    }
    .result-text {
        color: #666;
        border: 1px solid #ddd;
        border-radius: 6px;
        padding: 12px;
        margin-bottom: 20px;
    }
    .textarea {
        font-size: 16px;
        color: #000;
        font-family: '微软雅黑', Courier, monospace;
    }
    .el-button {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%; 
        height: 45px; 
        line-height: 45px; 
        margin-top: 20px;
    }
    .el-button span {
        margin-top: 0;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="wrap">
        <el-form ref="form" class="form" :model="form" label-width="90px">
            <el-form-item label="选择线路">
              <el-select v-model="form.line" placeholder="请选择选择线路" @change="changeSelect">
                <el-option :label="item.label" v-for="(item, index) in lineList" :key="index" :value="item.label"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="账号密码">
                <el-input type="text" spellcheck="false" clearable @clear="clear" @input="inputValue" placeholder="请粘贴账号密码" v-model="form.content"></el-input>
              </el-form-item>
          </el-form>
          <div class="result" v-if="result">
            <div class="title"> 结果如下：</div>
            <el-input class="textarea" spellcheck="false" type="textarea" :rows="20" placeholder="" v-model="result"></el-input>
            <el-button type="primary" @click="handleCopy">复制</el-button>
          </div>
    </div>

  </div>

  <!-- 引入 Vue -->
  <script src="https://unpkg.com/vue@2.7.16/dist/vue.js"></script>
  <!-- 引入 Element UI -->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>

  <script>
    new Vue({
      el: '#app',
      data() {
        return {
          textToCopy: '',
          notificationVisible: false,
          lineList: [{
            label: 'Test'
          },{
            label: '12M'
          },{
            label: '24M'
          },{
            label: '36M'
          },{
            label: '48M'
          }],
          form: {
            line: '12M',
            content: ''
          },
          result: '',
          username: '',
          password: ''
        }
      },
      computed: {
        isDisabled(){
            return this.form.line && this.form.content
        }
      },
      methods: {
        onSubmit() {
            let { username, password } = this
            let originText = `Dear friend,
This is 7 lines ${this.form.line}

C: egygold.co 51001  ${username}  ${password}
C: egygold.co 51002  ${username}  ${password}
C: egygold.co 51003  ${username}  ${password}
C: egygold.co 51004  ${username}  ${password}
C: egygold.co 51005  ${username}  ${password}
C: egygold.co 51006  ${username}  ${password}
C: egygold.co 51007  ${username}  ${password}

===================================
How to Setup:for example Lines 1:
Server: egygold.co
Port: 51001
Account: ${username}
Password: ${password}
Note that the server address does not contain ' C: '`
this.result = originText
        },
        inputValue(val) {
            if(!val) {
                return this.result = ''
            }
            let trimmedStr = val.replace(/\s+/g, '');
            // 计算中间位置
            let middleIndex = Math.floor(trimmedStr.length / 2);

            // 截取两个字符串
            this.username = trimmedStr.substring(0, middleIndex);
            this.password = trimmedStr.substring(middleIndex);
            this.onSubmit()
        },
        clear() {
            this.result = ''
        },
        changeSelect() {
            
            this.onSubmit()
        },
        handleCopy(val) {
            console.log('val', val);
            this.copyTextToClipboard(this.result)
            this.$message({
                type: "success",
                message: "复制成功",
            });
        },
        copyTextToClipboard(text) {
            var textArea = document.createElement("textarea");
            textArea.style.position = 'fixed';
            textArea.value = text;
            document.body.appendChild(textArea);
            textArea.focus();
            textArea.select();

            try {
            document.execCommand('copy');
            console.log('Text copied to clipboard');
            } catch (err) {
            console.error('Unable to copy text to clipboard');
            }

            document.body.removeChild(textArea);
        },
      }
    });
  </script>
</body>
</html>
